package leetcode.list;

/**
 * 走过你来时的路
 *
 * @author mazouri
 * @create 2021-08-18 23:39
 */
public class _160_getIntersectionNode_doublePoint {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) return null;

        ListNode pA = headA, pB = headB;
        while (pA != pB) {
            pA = pA == null ? headB : pA.next;
            pB = pB == null ? headA : pB.next;
        }
        return pA;
    }
}
